package com.syyo.gulimall.coupon.controller;

//import org.springframework.security.access.prepost.PreAuthorize;

import com.syyo.common.domain.ResultVo;
import com.syyo.common.utils.ResultUtils;
import com.syyo.gulimall.coupon.domain.entity.CouponEntity;
import com.syyo.gulimall.coupon.domain.req.CouponReq;
import com.syyo.gulimall.coupon.service.CouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;


/**
 * 优惠券信息
 *
 * @author syyo
 * @email syyo@gmail.com
 * @date 2021-01-20 09:35:54
 */
@RefreshScope
@RestController
@RequestMapping("/coupon/coupon")
public class CouponController {

    @Value("${wang.name}")
    private String name;
    @Value("${wang.age}")
    private String age;

    @Autowired
    private CouponService couponService;

    /**
     * 新增
     */
    @PostMapping
    // @PreAuthorize("@syyo.check('system:coupon:add')")
    public ResultVo add(@RequestBody CouponReq req) {
        return ResultUtils.ok(couponService.add(req));
    }

    /**
     * 删除
     */
    @DeleteMapping("/{id}")
    // @PreAuthorize("@syyo.check('system:coupon:del')")
    public ResultVo del(@PathVariable("id") Integer id) {
        return ResultUtils.ok(couponService.del(id));
    }

    /**
     * 修改
     */
    @PutMapping
    // @PreAuthorize("@syyo.check('system:coupon:edit')")
    public ResultVo edit(@RequestBody CouponReq req) {
        return ResultUtils.ok(couponService.add(req));
    }

    /**
     * 信息
     */
    @GetMapping("/{id}")
    public ResultVo findOne(@PathVariable("id") Integer id) {
        return ResultUtils.ok(couponService.findOne(id));
    }

    /**
     * 列表
     */
    @GetMapping("/list/{pageNum}/{pageSize}")
    public ResultVo findAll(@PathVariable("pageNum") Integer pageNum,
                            @PathVariable("pageSize") Integer pageSize,
                            CouponReq req) {
        return ResultUtils.ok(couponService.findAll(pageNum, pageSize, req));
    }

    /**
     * 测试
     */
    @GetMapping("/member")
    public ResultVo membercoupon() {
        CouponEntity couponEntity = new CouponEntity();
        couponEntity.setCouponName("满100减10");
        return ResultUtils.ok(couponEntity);
    }

    /**
     * 测试
     */
    @GetMapping("/test")
    public ResultVo test() {
        HashMap<String, String> map = new HashMap<>();
        map.put("ww", name);
        map.put("zz", age);
        return ResultUtils.ok(map);
    }

}
